Release 10.1A: OpenEdge Development:
Messaging and ESB


Sending a message to a queue and receiving a message from a queue

The procedures example18.p and example19.p send and receive a message from a queue.

To send a message to a queue and receive a message from a queue:

  1. Create the GolfQueue queue using the SonicMQ Explorer. (See SonicMQ Programming Guide for information about creating queues.)
  2. Run example18.p to send a TextMessage to the GolfQueue, as shown:
  3. example18.p 
    /* Sends A Text message to a queue. */ 
    DEFINE VARIABLE ptpsession AS HANDLE. 
    DEFINE VARIABLE messageH AS HANDLE. 
    /* Creates a session object. */ 
    RUN jms/ptpsession.p PERSISTENT SET ptpsession ("-H localhost -S 5162 "). 
    RUN setBrokerURL IN ptpsession ("localhost:2506"). 
    RUN beginSession IN ptpsession. 
    /* Create a text message */ 
    RUN createTextMessage IN ptpsession (OUTPUT messageH).  
    RUN setText IN messageH ("Golf shoes on sale today."). 
    /* Sends the message to the "GolfQueue" queue */ 
    RUN sendToQueue IN ptpsession ("GolfQueue", messageH, ?, ?, ?). 
    RUN deleteMessage IN messageH. 
    RUN deleteSession IN ptpsession. 
    

  4. Run example19.p to receive a message from the GolfQueue, as shown:
  5. example19.p 
    /* Receives a Text message from a queue. */ 
    DEFINE VARIABLE ptpsession AS HANDLE. 
    DEFINE VARIABLE consumerH AS HANDLE. 
    /* Creates a session object. */ 
    RUN jms/ptpsession.p PERSISTENT SET ptpsession  
                                   ("-H localhost -S 5162 "). 
    RUN setBrokerURL IN ptpsession ("localhost:2506"). 
    RUN beginSession IN ptpsession. 
    /*  GolfQueue Messages are handled by the "golfHandler" procedure.  */ 
    RUN createMessageConsumer IN ptpsession ( 
                      THIS-PROCEDURE,    /* This proc will handle it */ 
                      "golfHandler",     /* name of internal procedure */ 
                      OUTPUT consumerH). 
    RUN receiveFromQueue IN ptpsession (
                      "GolfQueue",   /* name of queue */ 
                      ?,             /* No message selector */ 
                      consumerH).    /* Handles incoming messages*/ 
    /* Start receiving messages */ 
    RUN startReceiveMessages IN ptpsession. 
    /* Wait to receive the messages. Any other IO-blocked statements can be
       used for receiving messages.  
    */ 
    WAIT-FOR u1 OF THIS-PROCEDURE. 
    
    PROCEDURE golfHandler: 
    DEFINE INPUT PARAMETER messageH AS HANDLE.  
    DEFINE INPUT PARAMETER msgConsumerH AS HANDLE. 
    DEFINE OUTPUT PARAMETER replyH AS HANDLE. 
        /* Display the message - we assume that reply is not required. */ 
        DISPLAY "Message text: " DYNAMIC-FUNCTION('getText':U IN messageH) 
          FORMAT "x(70)". 
        RUN deleteMessage IN messageH. 
        APPLY "U1" TO THIS-PROCEDURE.  
    END. 
    


Copyright © 2005 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095